<?php


namespace App\Http\Controllers\Api\v1;


use App\common;
use App\Logic\InformationLogic;
use App\server\JwtServer;
use App\server\RedisServer;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

class InformationController extends Controller
{
    /**
     * 模拟登录成功获取token
     */
    public function getToken(Request $request){
        try {
            $params = $request->post();
            $JwtCache=JwtServer::jwtEncode($params['uid']);
            $redis=RedisServer::createRedisObject();
            $redis->select(11);
            $redis->setex('jwtToken',600,$JwtCache);
            $tokenCache=$redis->get('jwtToken');
            return common::success(20000,$tokenCache,'登录成功');
        }catch (\Exception $exception){
            return common::fail($exception->getMessage(),'');
        }
    }
    /**
     * 资讯信息展示列表
     */
    public function InformationList(){
        try {
            $Secondary=InformationLogic::Secondary();
            return common::success(20000,$Secondary,'资讯息展示成功');
        }catch (\Exception $exception){
            return common::fail('',"",$exception->getMessage());
        }
    }
    /**
     * 资讯信息添加
     */
    public function InformationAdd(Request $request){
        try {
            $SecondaryAdd=InformationLogic::SecondaryAdd($request);
            return common::success(20000,$SecondaryAdd,'资讯信息添加成功');
        }catch (\Exception $exception){
            return common::fail('',"",$exception->getMessage());
        }
    }

    /**
     * 资讯信息删除
     */
    public function InformationDel(Request $request){
        try {
            $fangId=$request->get('id');
            $secondaryMessage=InformationLogic::SecondaryDel($fangId);
            return common::success(20000,$secondaryMessage,'资讯信息删除成功');
        }catch (\Exception $exception){
            return common::fail('',"",$exception->getMessage());
        }
    }
    /**
     * 资讯信息查找
     */
    public function InformationSeek(Request $request){
        try {
            $keyword=$request->get('keyword');
            $SecondaryMessage=InformationLogic::SecondarySeek($keyword);
            return common::success(20000,$SecondaryMessage,'资讯信息搜索成功');
        }catch (\Exception $exception){
            return common::fail('',"",$exception->getMessage());
        }
    }
    /**
     * 资讯详情
     */
    public function InformationDetails(Request $request){
        try {
            $fangId=$request->get('id');
            $SecondaryMessage=InformationLogic::SecondaryDetails($fangId);
            return common::success(20000,$SecondaryMessage,'资讯详情展示成功');
        }catch (\Exception $exception){
            return common::fail('',"",$exception->getMessage());
        }
    }
    /**
     * 资讯修改
     */
    public function InformationUpdated(Request $request){
        try {
            $SecondaryMessageUpdated = $request->post();
            $SecondaryAdd=InformationLogic::SecondaryUpdated($SecondaryMessageUpdated);
            return common::success(20000,$SecondaryAdd,'资讯信息修改成功');
        }catch (\Exception $exception){
            return common::fail('',"",$exception->getMessage());
        }
    }
    /**
     * 资讯es搜索
     */
    public function InformationSearch(Request $request){
        try {
            $keyword=$request->get('keyword');
            $SecondaryMessage=InformationLogic::SecondarySearch($keyword);
            return common::success(20000,$SecondaryMessage,'资讯es搜索成功');
        }catch (\Exception $exception){
            return common::fail('',"",$exception->getMessage());
        }
    }
}
